define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'financial/user_deposit/index' + location.search,
                    edit_url: 'financial/user_deposit/edit',
                    show_url: 'financial/user_deposit/show',
                    multi_url: 'financial/user_deposit/multi',
                    import_url: 'financial/user_deposit/import',
                    table: 'user_deposit',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'uid', title: __('Uid')},
                        {field: 'phone', title: __('Phone'), operate:'BETWEEN'},
                        {field: 'integral', title: __('Integral'), operate:'BETWEEN'},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons:[
                                {
                                    name: 'edit',
                                    text: '审核',
                                    extend: 'data-area=\'["100%", "100%"]\'',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-magic',
                                    url: $.fn.bootstrapTable.defaults.extend.edit_url,
                                    visible: true,
                                    visible: function (row){
                                        if (row.status != 0)
                                        {
                                            return false;
                                        }else{
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'show',
                                    text: '审核详情',
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    icon: 'fa fa-magic',
                                    extend: 'data-area=\'["100%", "100%"]\'',
                                    url: $.fn.bootstrapTable.defaults.extend.show_url,
                                    visible: function (row){
                                        if (row.status != 0)
                                        {
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
